Import cal3d

Class CalCoreAnimation

	Field m_listCallbacks:CalCallbackRecord[]
	Field m_duration:Float
	Field m_listCoreTrack:CalCoreTrack[]
	Field m_name:String
	Field m_filename:String
	
	
	Method New()
	
		m_listCallbacks = New CalCallbackRecord[0]
		m_duration = 0
		m_listCoreTrack = New CalCoreTrack[0]
		m_name = "Animation"
		m_filename = ""
	End
	
	Method addCoreTrack:Bool(coreTrack:CalCoreTrack)
	
		m_listCoreTrack = m_listCoreTrack.Resize(m_listCoreTrack.Length+1)
		m_listCoreTrack[m_listCoreTrack.Length-1] = coreTrack
		Return True
	End
	
	Method getCoreTrack:CalCoreTrack(coreBoneId:Int)
		For Local iCoreTrack:Int = 0 To m_listCoreTrack.Length-1
			' get the core track
			local coreTrack:CalCoreTrack = m_listCoreTrack[iCoreTrack]
	
			' check if we found the matching core bone
			If coreTrack.getCoreBoneId() = coreBoneId Then
				Return coreTrack
			Endif
		Next
	
		' no match found
		Return Null		
	End


	Method getDuration:Float()
		Return m_duration
	End

	Method setDuration:Void(duration:Float)
		m_duration = duration
	End
	
	Method scale:Void(factor:Float)
		For Local iCoreTrack:Int = 0 To m_listCoreTrack.Length-1
			m_listCoreTrack[iCoreTrack].scale(factor)
		Next		
	End
	
	Method setFilename:Void(filename:String)
		m_filename = filename
	End
	
	Method getFilename:String()
		Return m_filename
	End
	
	Method setName:Void(name:String)
		m_name = name
	End
	
	Method getName:String()
		Return m_name
	End
	
	Method registerCallback:Void(callback:CalAnimationCallback, min_interval:Float)
		Local record:CalCallbackRecord = New CalCallbackRecord
		record.callback = callback
		record.min_interval = min_interval
		m_listCallbacks = m_listCallbacks.Resize(m_listCallbacks.Length+1)'push(record)	
		m_listCallbacks[m_listCallbacks.Length-1] = record	
	End
	
	Method removeCallback:Void(callback:CalAnimationCallback)
		Local cbr:CalCallbackRecord[] = New CalCallbackRecord[m_listCallbacks.Length-1]
		Local pos:Int = 0
		For Local i:Int = 0 To m_listCallbacks.Length-1
			If m_listCallbacks[i].callback <> callback then
				cbr[pos] = m_listCallbacks[i]
				pos=pos+1
			Endif
		Next
		m_listCallbacks = cbr
			
	End
	
	Method getCallbackList:CalCallbackRecord[]()
		Return m_listCallbacks
	End
	
	Method getTrackCount:Int()
		Return m_listCoreTrack.Length
	End
	
	Method getListCoreTrack:CalCoreTrack[]()
		Return m_listCoreTrack
	End
	
	Method getTotalNumberOfKeyframes:Int()
		Local nbKeys:Int = 0
		For Local iCoreTrack:Int = 0 To m_listCoreTrack.Length-1
			Local coreTrack:CalCoreTrack = m_listCoreTrack[iCoreTrack]
			nbKeys += coreTrack.getCoreKeyframeCount()
		Next
	
		return nbKeys		
	End
	
	
End Class


Class CalCallbackRecord
	
	Field callback:CalAnimationCallback
	Field min_interval:Float
	
	Method New()
		callback = New CalAnimationCallback()
		min_interval = 0
	End
	
	Method New(cac:CalAnimationCallback,minint:Float)
	
		callback = cac
		min_interval = minint	
	End
	
	
End